*
* COVARIATE BALANCE
*
set varabbrev off, permanently
clear all
use epfipc2006-2019plus.dta
*
global listtotal gasto1-gasto12 year2-year13 ccaa2-ccaa18 income squaredm othehouse ///
       ttenure2-ttenure6 tsize2-tsize5 pdensity2-pdensity3 residshort nmembers nfemales ///
	   nforeign ndworkers n5_15 n16_24 n25_34 n35_64 n65_79 n80omas nstudies2-nstudies4 ///
	   nactive nincome labinc peninc uneinc capinc agemb femalemb foreignmb unemployedmb inactivemb
*
* Total expenditure
*
foreach var1 in T01 T12 T10 T21 {
	preserve
	keep if post==0 & `var1'!=.
	* propensity score estimation with survey weights
	logit `var1' $listtotal  [pweight=factor]
	predict double ps if e(sample)==1, pr
	drop if ps==.
	gen w=(`var1'+(((1-`var1')*ps)/(1-ps)))
	* Weights used for ATET estimation accounting for survey weights
	gen estweight=w*factor
	* imposing common support
	sum ps if `var1'==1
	scalar pmintreat=r(min)
	drop if ps<pmintreat & `var1'==0
	sum ps if `var1'==0
	scalar pmaxuntreat=r(max)
	drop if ps>pmaxuntreat & `var1'==1
	* checking common support visually
	twoway (kdensity ps if `var1'==1, lcolor(black))   ///
	(kdensity ps if `var1'==0 , lcolor(red) xtitle("Propensity score `: var label `var1''")  )  ///
	(kdensity ps if `var1'==0 [aweight=w], lcolor(blue) ytitle("Density") ), ///
	graphregion(fcolor(white)) ylab(,nogrid) name(`var1') legend(off)
	*graph export "`var1'.eps", replace
	restore
}
graph combine T10 T21 T01 T12 , graphregion(color(white)) cols(2) xsize(21) ysize(25)
*
* The End
*
